package com.study.rabbitmq.three;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.study.rabbitmq.util.RabbitUtil;
import javafx.concurrent.Task;

import java.io.IOException;
import java.util.Scanner;

/**
 * 消息在手动应答时是不丢失的，放回队列中重新消费
 * @Author chenyeqing
 * @Date 2021/9/2 22:08
 */
public class Task02 {

    /**
     * 队列名称
     */
    public static final String TASK_QUEUE_NAME = "ack_queue";

    public static void main(String[] args) throws IOException {
        Channel channel =  RabbitUtil.getChannel();

        // 声明队列
        channel.queueDeclare(TASK_QUEUE_NAME, false, false, false, null);

        // 从控制台中输入信息
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            // MessageProperties.PERSISTENT_TEXT_PLAIN 消息持久化
            channel.basicPublish("", TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes());
            System.out.println("生产者发出消息：" + message);
        }
    }
}
